﻿@model IEnumerable<com.fmtx.Model.Picture>
@{
    ViewBag.Title = "Detail";
    var isowner = Convert.ToInt32(Html.ViewContext.RouteData.Values["uid"]) == LoginModel.User.Uid;
}
@Styles.Render("~/js/prettyPhoto/css")
<style>
    label {
       color: rgb(151, 149, 149)
    }
</style>
<div class="container" >
    <fieldset>
        <legend style="font-size:inherit;" >
          <a rel="tooltip" data-original-title="返回列表" href="/@Html.ViewContext.RouteData.Values["uid"]/photo" >相册列表</a> >> <label style="color:#000;display:initial;padding-right:20px;" >@ViewBag.bean.Name </label> 
            @if(isowner){
            <button class="btn" onclick="openuploadbox()" ><i class="icon-upload"></i>上传</button>
            }
            </legend>
        <div class="control-group row-fluid" style="margin-top:0px;">
            <div class="span10" >
                <ul class="unstyled userphoto">
                    @if(Model!=null)
                    {
                        foreach (var item in Model)
                        {
                            <li id="li_@item.Id" data-title="@item.Title" data-content="@item.Content" >
                                <a title="@item.Title" rel="prettyPhoto[@item.TypeId]" href="@StaticCs.ImageUrl/img/Artwork?file=@item.PicAddress" >
                                    <img src="@StaticCs.ImageUrl/img/OnlyCache?m=HeightAndWidth&w=195&h=200&file=@item.PicAddress" />
                                </a>
                                <span >@item.Title &nbsp;</span><br />
                                @if(isowner){
                                <a style="line-height:20px;" onclick="editPicture(@item.Id)"><i class="icon-edit"></i>编辑</a>
                                <a style="line-height:20px;" onclick="delPicture(@item.Id)" ><i class="icon-trash"></i>删除</a>
                                <a style="line-height:20px;" onclick="setFrontCover(@item.Id)" ><i class="icon-home"></i>设为封面</a>
                                }
                            </li>
                        }
                    }
                </ul>
                <div class="clear"></div>
            </div>
            <div class="span2 well" style="width:230px;margin-left:0px;" >
                <fieldset>
                    <legend style="margin-bottom: 0px;">相册属性 
                        @if(isowner){
                        <button onclick="openedittypebox()" style="float:right;" class="btn" >编辑</button>
                        }
                    </legend>
                    <div class="control-group">
                      <div class="controls">
                          <img id="FrontCover" src="@StaticCs.ImageUrl/img/OnlyCache?m=OverCut&w=195&h=165&file=@ViewBag.bean.FrontCover" />
                      </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="CityName">城市</label>
                      <div class="controls">
                          @ViewBag.bean.CityName
                      </div>
                    </div>
                    <div class="control-group">
                       <label class="control-label" for="PlaceName">景点</label>
                        <div class="controls">
                            @ViewBag.bean.PlaceName
                      </div>
                    </div>
                    <div class="control-group">
                       <label class="control-label" for="PlaceName">简介</label>
                        <div class="controls">
                          @ViewBag.bean.Summary
                      </div>
                    </div>
                    <div class="control-group">
                       <label class="control-label" for="PlaceName">标签</label>
                        <div class="controls">
                          @ViewBag.bean.KeyWord
                      </div>
                    </div>
                    <div style="clear:both;"></div>
                </fieldset>
            </div>
        </div>
        </fieldset>
</div>
<div style="clear:both;"></div>

<script type="text/template" id="templateuploadbox">
    <div style="width: 410px;" class="span11 row-fluid">
    <div class="tab-pane" id="profile">
        <div class="span6">
            <div id="bootstrapped-fine-uploader" style="width: 240px;">
            </div>
        </div>
    </div>
    <div style="clear: both;"></div>
    <form method="post" action="/@Html.ViewContext.RouteData.Values["uid"]/photo/SaveImage" id="formupimage" >
    <div style="width: 88%; margin: 5px;display:none;">
        <input type="submit" class="btn btn-primary" style="float: right;" value="确定" />
        <div style="clear: both;"></div>
    </div>
    <input name="typeid" type="hidden" value="@ViewBag.bean.Id" />
    <input id="files" name="images" type="hidden" value="0" />
    <div id="showimg" style="display: none; width: 200px;"></div>
    </form>
</div>
</script>
<script type="text/template" id="templateedit">
    <div class="form-horizontal" >
    <div class="control-group">
      <label style="width:inherit;" class="control-label" for="input01">照片名称</label>
      <div style="margin-left:50px;" class="controls">
        <input type="text" id="txtname" placeholder="照片名称" class="input-medium" name="Title" value="{Title}"  />
      </div>
    </div>
    <div class="control-group">
      <label style="width:inherit;" class="control-label" for="input01">简介</label>
      <div style="margin-left:50px;" class="controls">
            <textarea id="txtSummary" class="input-xlarge" placeholder="请输入相册介绍" name="Summary">{Summary}</textarea>
      </div>
    </div>
    <div class="form-actions" style="background-color:#fff;border-top:none;" >
        <button type="button" onclick="editpicbody({Id})" class="btn btn-primary">保存更改</button>
        <button class="btn" onclick="closemodal()" >取消</button>
    </div>
</div>
</script>

@section scripts{

    @Scripts.Render("~/js/jqprettyPhoto")
    <script type="text/javascript" >
        var baseurl="@StaticCs.ImageUrl";
        $(document).ready(function(){
            $("a[rel^='prettyPhoto']").prettyPhoto({ social_tools: "" });
        });
        function openuploadbox() {
            showloading();
            $("#basic-modal-content").html($("#templateuploadbox").html()).modal({ position: { at: "top" }, title: '上传图片' });
            createUploader(submit,true);
        }

        function submit(imgs)
        {
            $("#files").val(imgs.join(","));
            $("#formupimage").submit();
        }

        function openedittypebox()
        {
            showloading();
            $.get("/Tool/Picture/OpenEditTypeBox", { id: @ViewBag.bean.Id}, function (html) {
                $("#basic-modal-content").html(html).modal({ title: '编辑属性' });
            });
        }

        function setFrontCover(id)
        {
            showloading();
            $.get("/Action/Picture/SetFrontCover",{id:id},function(data){
                if(data.success)
                {
                    showinfo("设置成功！");
                    $("#FrontCover").attr("src",baseurl+"/img/OnlyCache?m=OverCut&w=195&h=165&file="+data.pic);
                }else if(data.error==1001){
                    showloginDialog();
                }else{
                    showerror("设置失败！");
                }
            });
        }

        function editPicture(id)
        {
            var title=$("#li_"+id).attr("data-title");
            var body=$("#li_"+id).attr("data-content");
            $("#basic-modal-content").html($("#templateedit").html().fill({Id:id,Title:title,Summary:body})).modal({ title: '照片编辑' });;
        }

        function editpicbody(id)
        {
            showloading();
            var Title=$("#txtname").val();
            var Summary=$("#txtSummary").val();
            $.post("/Action/Picture/EditPicture",{title:Title,content:Summary,id:id},function(data){
                if(data.error==0)
                {
                    $("#li_"+id).attr("data-title",Title);
                    $("#li_"+id).attr("data-content",Summary);
                    $("#li_"+id).find("a").eq(0).attr("title",Title);
                    $("#li_"+id).find("a").eq(1).text(Title);
                    showinfo("修改成功！");
                    closemodal();
                }else if(data.error==1001){
                    showloginDialog();
                }else{
                    showerror("修改失败！");
                }
            });
        }

        function delPicture(id)
        {
            setconfirm("确定要删除吗？",function(){
                showloading();
                $.post("/Action/Picture/DelPictrue",{id:id},function(data){
                    if(data.error==0)
                    {
                        showinfo("删除成功！");
                        $("#li_"+id).remove();
                    }else if(data.error==1001){
                        showloginDialog();
                    }else{
                        showerror("删除失败！");
                    }
                });
            });
        }
        setucentmenu("photo");
     </script>    
}